rbtree: Add _gtk_rbtree_contains()
authorBenjamin Otte <otte@redhat.com>
Sat, 10 Dec 2011 01:02:29 +0000 (02:02 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 10 Dec 2011 07:00:25 +0000 (08:00 +0100)
It's useful in a bunch of places, so split it out

gtk/gtkrbtree.c
gtk/gtkrbtree.h

index d6dc93833f5c8e7adbb502b2ecdfae766fba237d..1b6d7f5cc8f61b690268cfd262fcb8275868361a 100644 (file)
@@ -880,6 +880,31 @@ _gtk_rbtree_reorder (GtkRBTree *tree,
   g_free (nodes);
 }
 
+/**
+ * _gtk_rbtree_contains:
+ * @tree: a tree
+ * @potential_child: a potential child of @tree
+ *
+ * Checks if @potential_child is a child (direct or via intermediate
+ * trees) of @tree.
+ *
+ * Returns: %TRUE if @potentitial_child is a child of @tree.
+ **/
+gboolean
+_gtk_rbtree_contains (GtkRBTree *tree,
+                      GtkRBTree *potential_child)
+{
+  g_return_val_if_fail (tree != NULL, FALSE);
+  g_return_val_if_fail (potential_child != NULL, FALSE);
+
+  do {
+    potential_child = potential_child->parent_tree;
+    if (potential_child == tree)
+      return TRUE;
+  } while (potential_child != NULL);
+
+  return FALSE;
+}
 
 gint
 _gtk_rbtree_node_find_offset (GtkRBTree *tree,
index 173b141beb14bdcb7f424aa42a4921552d1f21f6..931f7c69a11ba55161caf822400e3ceffcb22c2d 100644 (file)
@@ -117,6 +117,8 @@ gboolean   _gtk_rbtree_is_nil           (GtkRBNode              *node);
 void       _gtk_rbtree_reorder          (GtkRBTree              *tree,
                                         gint                   *new_order,
                                         gint                    length);
+gboolean   _gtk_rbtree_contains         (GtkRBTree              *tree,
+                                         GtkRBTree              *potential_child);
 GtkRBNode *_gtk_rbtree_find_count       (GtkRBTree              *tree,
                                         gint                    count);
 void       _gtk_rbtree_node_set_height  (GtkRBTree              *tree,